home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_08_02
/
8n02056a
< prev
next >
Wrap
Text File
|
1990-02-28
|
3KB
|
114 lines
*****Listing 7*****
001 #include <stdio.h>
002 #include <stdarg.h>
003 #include "utility.h"
004
005 /********************************************************/
006 /* CLASS GRAPHICAL OBJECT */
007
008 class graph_obj {
009 public:
010 int y;
011 int x;
012 void init(int y, int x);
013 void move(int y, int x);
014 virtual void draw(int color){};
015 };
016
017 void graph_obj::init(int y2, int x2)
018 {
019 y = y2;
020 x = x2;
021 }
022
023 void graph_obj::move(int y_delta, int x_delta)
024 {
025 draw(g_black);
026 x += x_delta;
027 y += y_delta;
028 draw(g_white);
029 }
030
031 /********************************************************/
032 /* CLASS CIRCLE */
033
034 class circle: public graph_obj {
035 public:
036 int radius;
037 void init(int y, int x, int radius);
038 void draw(int color);
039 };
040
041 void circle::init(int y2, int x2, int radius2)
042 {
043 graph_obj::init(y2, x2);
044 radius = radius2;
045 draw(g_white);
046 }
047
048 void circle::draw(int color)
049 {
050 g_circle(y, x, radius, color);
051 }
052
053 /********************************************************/
054 /* CLASS SQUARE */
055
056 class square: public graph_obj {
057 public:
058 int size;
059 void init(int y, int x, int radius);
060 void draw(int color);
061 };
062
063 void square::init(int y2, int x2, int size2)
064 {
065 graph_obj::init(y2, x2);
066 size = size2;
067 draw(g_white);
068 }
069
070 void square::draw(int color)
071 {
072 g_square(y, x, size, color);
073 }
074
075 /********************************************************/
076 /* CLASS DOUBLE_CIRCLE */
077
078 class double_circle: public circle {
079 public:
080 void draw(int color);
081 };
082
083 void double_circle::draw(int color)
084 {
085 g_circle(y, x, radius, color);
086 g_circle(y, x, radius - 2, color);
087 }
088
089 /********************************************************/
090
091 int main(void);
092 int main(void)
093 {
094 int x;
095 circle c1;
096 square s1;
097 double_circle dc1;
098 g_init();
099 c1.init(40, 40, 20);
100 s1.init(40, 100, 20);
101 dc1.init(40, 160, 20);
102 for (x = 0; x < 100; ++x) {
103 c1.move(1, 1);
104 s1.move(1, 0);
105 dc1.move(0, -1);
106 }
107 cleanup();
108 return (0);
109 }